﻿{
    $project: {
        
        _id: "$_id",
        CompanyId: "$CompanyId",
        MatrixId: "$MatrixId",
        PeerGroupId: "$PeerGroupId",
        ParentGroupId: "$ParentGroupId",
        PeerGroupName: "$PeerGroupName",
        WorkingVersion : "$WorkingVersion",
        CompanyName : "$CompanyName ",

        
            E_1: "$E_1",
            E_2: "$E_2",
            E_3: "$E_3",

            G_1: "$G_1",
            G_2: "$G_2",
            G_3: "$G_3",

            S_1: "$S_1",
            S_2: "$S_2",
            S_3: "$S_3",
            S_4: "$S_4",
            S_5: "$S_5",

     
            E: {
            Weight: "$E.Weight",
            Score: {
                    $add: [
                          { $ifNull: [{ $multiply: [0.001, '$E_1.Score', '$E_1.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: [0.001, '$E_2.Score', '$E_2.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: [0.001, '$E_3.Score', '$E_3.Weight'] }, 0] },
                    ]
            }
            },
        G: {
                Weight: "$G.Weight",
                Score: {
                $add: [
                      { $ifNull: [{ $multiply: [0.001, '$G_1.Score', '$G_1.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$G_2.Score', '$G_2.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$G_3.Score', '$G_3.Weight'] }, 0] },
                ]
                }
        },
        S: {
                Weight: "$S.Weight",
                Score: {
                $add: [
                      { $ifNull: [{ $multiply: [0.001, '$S_1.Score', '$S_1.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$S_2.Score', '$S_2.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$S_3.Score', '$S_3.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$S_4.Score', '$S_4.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$S_5.Score', '$S_5.Weight'] }, 0] },
                ]
                }
        },
        P: {
                Weight: "$P.Weight",
                Score: {
                $add: [
                      { $ifNull: [{ $multiply: [0.001, '$P_1.Score', '$P_1.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_2.Score', '$P_2.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_3.Score', '$P_3.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_4.Score', '$P_4.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_5.Score', '$P_5.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_6.Score', '$P_6.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_7.Score', '$P_7.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_8.Score', '$P_8.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_9.Score', '$P_9.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_10.Score', '$P_10.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_11.Score', '$P_11.Weight'] }, 0] },
                      { $ifNull: [{ $multiply: [0.001, '$P_12.Score', '$P_12.Weight'] }, 0] },
                ]
                }
        },

        }
}